<template>
  <div class="cloud" v-if="hotTagData.length > 0">
    <h2
      class="hometitle"
      :class="{ active: showCloud }"
      @click="toggleCloud"
    >
      标签云
    </h2>
    <transition name="slide-fade">
      <ul v-if="showCloud">
        <a v-for="item in hotTagData" :key="item.uid" href="javascript:void(0);" @click="goToList(item.uid)">
          {{ item.content }}
        </a>
      </ul>
    </transition>
  </div>
</template>

<script>

export default {
  name: "TagCloud",
  props: {
    hotTagData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      showCloud: false // 控制标签云显示的状态
    };
  },
  created() {
  },
  methods: {
    // 切换标签云显示状态
    toggleCloud() {
      this.showCloud = !this.showCloud;
    },
    // 跳转到搜索详情页
    goToList(uid) {
      let routeData = this.$router.resolve({ path: "/list", query: { tagUid: uid } });
      window.open(routeData.href, '_blank');
    }
  }
};
</script>

<style scoped>
.cloud {
  border-radius: 8px;
  position: relative;
  background-color: #fff;
  padding: 30px 30px 50px 30px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.cloud:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.hometitle {
  cursor: pointer;
  margin: 0;
  padding: 10px;
  background-color: #f5f5f5;
  border-radius: 8px;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.hometitle:hover {
  background-color: #e0e0e0;
}

.hometitle.active {
  background-color: #fff;
  color: #333;
}

/* 滑动显示效果 */
.slide-fade-enter-active, .slide-fade-leave-active {
  transition: opacity 0.5s, transform 0.5s;
}

.slide-fade-enter, .slide-fade-leave-to /* .slide-fade-leave-active in <2.1.8 */ {
  opacity: 0;
  transform: translateY(-10px);
}
</style>
